package cn.stylefeng.guns.modular.system.utils;

import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: lzy
 * @Description: 代码简化copy
 * @Date: CREATE IN 2019/5/14 10:44
 */
public class SimplifyCopyUtil<T,V> {
    private T t;
    private V v;
    Class<V> clazz;

    public SimplifyCopyUtil() {
    }

    public SimplifyCopyUtil(T t) {
        this.t = t;
    }

    public SimplifyCopyUtil(T t, Class<V> clazz) {
        this.t = t;
        this.clazz = clazz;
    }
    /**
     *
     *  传入DeviceSite
     *  传入SiteVO
     */
    public V getVO(){
		try {
			v = clazz.newInstance();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}  
        BeanUtils.copyProperties(t,v);
        return v;
    }

    /**
     *
     * @param obj1 List<对象>
     * @return
     */
    public List<V> getListByListVO(Object obj1){
        List<V> aa = new ArrayList<V>();
        List<T> listt = (List) obj1;
        for (T t1 : listt) {
        	try {
				v = clazz.newInstance();
	            BeanUtils.copyProperties(t1,v);
	            aa.add(v);
			} catch (InstantiationException | IllegalAccessException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
        }
        return aa;
    }

}
